package com.huawei.esdk.tp.northcommu.cxf.professional.convert;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;

import com.huawei.esdk.platform.common.SDKResult;
import com.huawei.esdk.platform.common.config.ConfigManager;
import com.huawei.esdk.platform.common.constants.ESDKErrorCodeConstant;
import com.huawei.esdk.platform.common.exception.SDKException;
import com.huawei.esdk.platform.common.utils.DateUtils;
import com.huawei.esdk.platform.common.utils.DurationUtils;
import com.huawei.esdk.platform.common.utils.StringUtils;
import com.huawei.esdk.tp.common.CipherUtils;
import com.huawei.esdk.tp.common.EnumRangeUtils;
import com.huawei.esdk.tp.common.ErrInfo;
import com.huawei.esdk.tp.cxf.enumgen.ConfStatusMapping;
import com.huawei.esdk.tp.cxf.enumgen.ContinuousPresenceMode;
import com.huawei.esdk.tp.cxf.enumgen.ContinuousPresenceModeEXMapping;
import com.huawei.esdk.tp.cxf.enumgen.DayOfWeekMapping;
import com.huawei.esdk.tp.cxf.enumgen.DialMode;
import com.huawei.esdk.tp.cxf.enumgen.DialModeMapping;
import com.huawei.esdk.tp.cxf.enumgen.FreeBusyState;
import com.huawei.esdk.tp.cxf.enumgen.FreeBusyStateMapping;
import com.huawei.esdk.tp.cxf.enumgen.MediaEncryptTypeMapping;
import com.huawei.esdk.tp.cxf.enumgen.ParticipantType;
import com.huawei.esdk.tp.cxf.enumgen.ParticipantTypeMapping;
import com.huawei.esdk.tp.cxf.enumgen.PresentationTypeMapping;
import com.huawei.esdk.tp.cxf.enumgen.RecurrenceFrequency;
import com.huawei.esdk.tp.cxf.enumgen.RecurrenceFrequencyMapping;
import com.huawei.esdk.tp.cxf.enumgen.SiteFrom;
import com.huawei.esdk.tp.cxf.enumgen.SiteFromMapping;
import com.huawei.esdk.tp.cxf.enumgen.SiteType;
import com.huawei.esdk.tp.cxf.enumgen.SiteTypeMapping;
import com.huawei.esdk.tp.domain.model.Conference;
import com.huawei.esdk.tp.domain.model.ConferenceStatus;
import com.huawei.esdk.tp.domain.model.PeriodicalConference;
import com.huawei.esdk.tp.domain.model.ScheduleConference;
import com.huawei.esdk.tp.domain.model.Site;
import com.huawei.esdk.tp.domain.model.SiteInConference;
import com.huawei.esdk.tp.domain.model.bean.AdhocConfFreeBusyState;
import com.huawei.esdk.tp.domain.model.bean.AdhocConfFreeBusyStateList;
import com.huawei.esdk.tp.domain.model.bean.AdhocConferences;
import com.huawei.esdk.tp.domain.model.bean.AdhocConferencesList;
import com.huawei.esdk.tp.domain.model.bean.CallEndPoint;
import com.huawei.esdk.tp.domain.model.bean.ContinuousPresenceCapability;
import com.huawei.esdk.tp.domain.model.bean.ContinuousPresenceParam;
import com.huawei.esdk.tp.domain.model.bean.DateTimeRange;
import com.huawei.esdk.tp.domain.model.bean.FreeBusyInfo;
import com.huawei.esdk.tp.domain.model.bean.MultiPointCDR;
import com.huawei.esdk.tp.domain.model.bean.MultiPointCDRQueryConfig;
import com.huawei.esdk.tp.domain.model.bean.MultiPointCDRResult;
import com.huawei.esdk.tp.domain.model.bean.PageParam;
import com.huawei.esdk.tp.domain.model.bean.PagedList;
import com.huawei.esdk.tp.domain.model.bean.PagesInfo;
import com.huawei.esdk.tp.domain.model.bean.PointToPointCDR;
import com.huawei.esdk.tp.domain.model.bean.PointToPointCDRQueryConfig;
import com.huawei.esdk.tp.domain.model.bean.QueryCondition;
import com.huawei.esdk.tp.domain.model.bean.QuerySites;
import com.huawei.esdk.tp.domain.model.bean.SiteMCU;
import com.huawei.esdk.tp.domain.model.bean.SortField;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.AddSiteToConfExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.AdhocConfFreeBusyStateEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.AdhocConferenceEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.ConferenceInfoEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.ConferenceStatusEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.DoubleFilterEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.EditRecurrenceConferenceEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.EditRecurrenceConferenceExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.EditScheduledConfEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.EditScheduledConfExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.ErrorInfoEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.FilterBaseEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.FreeBusyStateEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.GetContinuousPresenceInfoExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.GetContinuousPresenceParamExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.IntFilterEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.MultiPointCDREx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.MultiPointCDRQueryConfigEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.PageParamEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.PagesInfoEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.PointToPointCDREx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.PointToPointCDRQueryConfigEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryAdhocConfFreeBusyExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryAdhocConferencesEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryAdhocConferencesExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryConfSiteMCUExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryConfSitesStatusExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryConferencesStatusExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryConfigEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryMultiPointCDRExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryPointToPointCDREx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QueryPointToPointCDRExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QuerySiteStatusExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.QuerySitesExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.RecurrenceConfInfoEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.ScheduleConfEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.ScheduleConfExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.ScheduleRecurrenceConferenceEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.ScheduleRecurrenceConferenceExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.SiteAccessInfoEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.SiteFreeBusyStatesEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.SiteInfoEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.SiteMCUEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.SiteStatusEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.SortItemEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.StringFilterEx;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.SynchAdhocConfFreeBusyExResponse;
import com.huawei.esdk.tp.northcommu.cxf.professional.gen.SynchSiteStatusExResponse;

/** * @author w00208247 * * */
public class TPProfessionalConfMgrConvert
{
    /**
     * 预约会议，预约周期会议，修改会议 ConferenceInfoEx赋值 预约会议，预约带匿名会场的会议，修改会议
     * 三个方法传入的参数除了类型不一致以外，里面的内容完全一致 将三个bean的赋值合并 北向soapbean转北向领域bean，用于赋值的情况
     */
    private void conferenceInfoExSoap2model(ConferenceInfoEx conferenceInfoEx, ScheduleConference conference)
        throws SDKException
    {
        // 通过领域模型将行业相关bean转到产品无关bean
        String confName = conferenceInfoEx.getName();
        XMLGregorianCalendar beginTime = conferenceInfoEx.getBeginTime();
        Duration duration = conferenceInfoEx.getDuration();
        String rate = conferenceInfoEx.getRate();
        // 预约会议，预约静态会议的时候confId是0
        String confId = conferenceInfoEx.getConfId();
        conference.setId(confId);
        List<SiteInConference> siteInConferences = new ArrayList<SiteInConference>();
        conference.setName(confName);
        conference.setBeginTime(DateUtils.toDate(beginTime));
        // 将用户输入的duration类型转换成long，分钟为单位
        conference.setLength(DurationUtils.duration2int(duration));
        conference.setAccessCode(conferenceInfoEx.getAccessCode());
        
        //R3修改
        if (!StringUtils.isEmpty(conferenceInfoEx.getPassword()))
        {
            String encryptedPwd = CipherUtils.decodeFromBase64(conferenceInfoEx.getPassword());
            if (null != encryptedPwd && !encryptedPwd.isEmpty())
            {
                conference.setPassword(encryptedPwd);
            }
            else
            {
                SDKException sdkException = new SDKException(ErrInfo.SDK_TP_PASSWORD_DECODE_ERRORDESC);
                sdkException.setSdkErrCode(ErrInfo.SDK_TP_PASSWORD_DECODE_ERRORCODE);
                throw sdkException;
            }
        }
        else
        {
            conference.setPassword(conferenceInfoEx.getPassword());
        }
        
        //R3新增参数
        if (!StringUtils.isEmpty(conferenceInfoEx.getChairmanPassword()))
        {
            String encryptedPwd = CipherUtils.decodeFromBase64(conferenceInfoEx.getChairmanPassword());
            if (null != encryptedPwd && !encryptedPwd.isEmpty())
            {
                conference.setChairmanPassword(encryptedPwd);
            }
            else
            {
                SDKException sdkException = new SDKException(ErrInfo.SDK_TP_PASSWORD_DECODE_ERRORDESC);
                sdkException.setSdkErrCode(ErrInfo.SDK_TP_PASSWORD_DECODE_ERRORCODE);
                throw sdkException;
            }
        }
        else
        {
            conference.setChairmanPassword(conferenceInfoEx.getChairmanPassword());
        }
        // 判断枚举类型是否超出范围
        EnumRangeUtils.enumRange(conferenceInfoEx.getMediaEncryptType(), MediaEncryptTypeMapping.class);
        conference.setMediaEncryptType(conferenceInfoEx.getMediaEncryptType());
        
        //R3修改
        conference.setAuxVideoFormat(conferenceInfoEx.getAuxVideoFormat());
        conference.setAuxVideoProtocol(conferenceInfoEx.getAuxVideoProtocol());
        
        conference.setCpResouce(conferenceInfoEx.getCpResouce());
        conference.setRate(rate);
        
        // boolean类型的边界值判断，只允许输入0,1
        EnumRangeUtils.enumRange(conferenceInfoEx.getIsRecording(), Boolean.class);
        conference.setIsRecording(conferenceInfoEx.getIsRecording());
        conference.setRecorderAddr(conferenceInfoEx.getRecorderAddr());
        
        // boolean类型的边界值判断，只允许输入0,1
        EnumRangeUtils.enumRange(conferenceInfoEx.getIsLiveBroadcast(), Boolean.class);
        conference.setIsLiveBroadcast(conferenceInfoEx.getIsLiveBroadcast());
        
        EnumRangeUtils.enumRange(conferenceInfoEx.getPresentation(), PresentationTypeMapping.class);
        conference.setPresentation(conferenceInfoEx.getPresentation());
        conference.setBillCode(conferenceInfoEx.getBillCode());
        SiteInConference site = null;
        List<SiteInfoEx> siteInfos = conferenceInfoEx.getSites();
        for (SiteInfoEx siteInfo : siteInfos)
        {
            // 北向soap bean转领域模型
            if (null != siteInfo)
            {
                site = siteInfoExSoap2model(siteInfo, null);
            }
            siteInConferences.add(site);
        }
        
        // R5C00新增
        conference.setMainSiteUri(conferenceInfoEx.getMainSiteUri());
        
        if (null != conferenceInfoEx.getConferenceNotice())
        {
            conference.setCreatorEmail(conferenceInfoEx.getConferenceNotice().getEmail());
            conference.setEmailContent(conferenceInfoEx.getConferenceNotice().getContent());
        }
        // end
        
        conference.setSites(siteInConferences);
    }
    
    /**
     * 会场信息转换 给SiteInfoEx赋值 北向soapbean转北向领域bean 会场信息转换 北向soapbean转北向领域bean
     */
    private SiteInConference siteInfoExSoap2model(SiteInfoEx siteInfo, SiteAccessInfoEx siteAccessInfoEx)
        throws SDKException
    {
        SiteInConference site = new SiteInConference();
        site.setUri(siteInfo.getUri());
        site.setName(siteInfo.getName());
        
        // 判断SiteType是否在用户可选的枚举范围之内
        EnumRangeUtils.enumRange(siteInfo.getType(), SiteTypeMapping.class);
        SiteType siteType = SiteTypeMapping.int2Enum(siteInfo.getType());
        site.setSiteType(null == siteType ? null : siteType.toString());
        
        // 判断SiteFormat是否在用户可选的枚举范围之内
        EnumRangeUtils.enumRange(siteInfo.getFrom(), SiteFromMapping.class);
        SiteFrom siteFrom = SiteFromMapping.int2Enum(siteInfo.getFrom());
        site.setFrom(null == siteFrom ? null : siteFrom.toString());
        
        // 判断DialMode是否在用户可选的枚举范围之内
        EnumRangeUtils.enumRange(siteInfo.getDialingMode(), DialModeMapping.class);
        DialMode dialMode = DialModeMapping.int2Enum(siteInfo.getDialingMode());
        site.setDialingMode(null == dialMode ? null : dialMode.toString());
        site.setRate(siteInfo.getRate());
        
        site.setVideoFormat(siteInfo.getVideoFormat());
        
        site.setVideoProtocol(siteInfo.getVideoProtocol());
        
        // R5C00，该字段未使用，需要删除
        // site.setStatus(siteInfo.getStatus());
        
        // R5C00新增
        ParticipantType participantType = ParticipantTypeMapping.int2Enum(siteInfo.getParticipantType());
        site.setParticipantType(null == participantType ? null : participantType.toString());
        site.setIsLockVideoSource(siteInfo.getIsLockVideoSource());
        // R5C00 end
        
        return site;
    }
    
    /**
     * 预约周期会议
     */
    
    /**
     * 预约会议，预约带匿名会场的会议，修改会议 三个方法传入的参数除了类型不一致以外，里面的内容完全一致 将三个bean的赋值合并
     * 北向soapbean转北向领域bean，用于赋值的情况
     */
    private PeriodicalConference scheduleRecurrenceConfCommSoap2model(ScheduleRecurrenceConferenceEx parameters)
        throws SDKException
    {
        // 通过领域模型将行业相关bean转到产品无关bean
        PeriodicalConference conference = new PeriodicalConference();
        // 周期会议中与普通会议通用的属性赋值
        ConferenceInfoEx conferenceInfoEx = parameters.getScheduleConf();
        conferenceInfoExSoap2model(conferenceInfoEx, conference);
        
        // 周期会议特有的属性赋值
        RecurrenceConfInfoEx recurrenceConfInfoEx = parameters.getScheduleConf();
        
        // 判断RecurrenceFrequency是否在用户可选的枚举范围之内
        EnumRangeUtils.enumRange(recurrenceConfInfoEx.getFrequency(), RecurrenceFrequencyMapping.class);
        RecurrenceFrequency recurrenceFrequency =
            RecurrenceFrequencyMapping.int2Enum(recurrenceConfInfoEx.getFrequency());
        conference.setFrequency(null == recurrenceFrequency ? null : recurrenceFrequency.toString());
        conference.setInterval(recurrenceConfInfoEx.getInterval());
        
        // recurrenceConfInfoEx.getWeekDays()中List的每个值的返回是0~6之间
        for (Integer week : recurrenceConfInfoEx.getWeekDays())
        {
            EnumRangeUtils.enumRange(week, DayOfWeekMapping.class);
        }
        conference.setWeekDays(recurrenceConfInfoEx.getWeekDays());
        conference.setWeekDay(recurrenceConfInfoEx.getWeekDay());
        conference.setMonthDay(recurrenceConfInfoEx.getMonthDay());
        conference.setCount(recurrenceConfInfoEx.getCount());
        conference.setEndDate(DateUtils.toDate(recurrenceConfInfoEx.getEndDate()));
        
        // R5C00修改，时区为可选字段，为向前兼容，用户升级后不传的该字段的话，我们默认提供Asia/Shanghai时区
        if (StringUtils.isEmpty(recurrenceConfInfoEx.getTimeZone()))
        {
            String defaultTimeZone = ConfigManager.getInstance().getValue("default.timeZone");
            conference.setTimeZone(defaultTimeZone);
        }
        else
        {
            conference.setTimeZone(recurrenceConfInfoEx.getTimeZone());
        }
        // end
        
        return conference;
    }
    
    /**
     * * 根据领域返回对北向soapbean值赋值
     * @param result /** * @param scheduleConfResponse /** * @return
     */
    private void setConferenceEx(long errorCode, ScheduleConference conference,
        ScheduleConfExResponse scheduleConfResponse)
    {
        scheduleConfResponse.setResultCode((int)errorCode);
        // 从返回值中取出返回消息，赋给北向soapbean
        // 首先判断返回值是否为0，如果不为0，直接返回错误码
        if (errorCode != 0)
        {
            return;
        }
        ConferenceInfoEx conferenceInfo = new ConferenceInfoEx();
        conferenceInfo.setConfId(conference.getId() + "");
        
        List<SiteInConference> siteInConferences = conference.getSites();
        SiteInfoEx siteInfo = null;
        for (SiteInConference siteInConference : siteInConferences)
        {
            siteInfo = new SiteInfoEx();
            
            siteInfo.setUri(siteInConference.getUri());
            siteInfo.setName(siteInConference.getName());
            
            // 返回多个accessCode，考虑多MCU的情况
            conferenceInfo.setAccessCode(siteInConference.getAccessCode());
            conferenceInfo.getSites().add(siteInfo);
        }
        
        //Add in R3
        conferenceInfo.setRecorderAddr(conference.getRecorderAddr());
        
        scheduleConfResponse.setConferenceInfo(conferenceInfo);
    }
    
    private void setRecurrenceConfInfo(long errorCode, ScheduleConference conference,
        ScheduleRecurrenceConferenceExResponse scheduleConfResponse)
    {
        scheduleConfResponse.setResultCode((int)errorCode);
        // 从返回值中取出返回消息，赋给北向soapbean
        // 首先判断返回值是否为0，如果不为0，直接返回错误码
        if (errorCode != 0)
        {
            return;
        }
        RecurrenceConfInfoEx conferenceInfo = new RecurrenceConfInfoEx();
        conferenceInfo.setConfId(conference.getId() + "");
        
        List<SiteInConference> siteInConferences = conference.getSites();
        
        // R5C00，周期会议不再需要返回会场对象
        //SiteInfoEx siteInfo = null;
        SiteAccessInfoEx siteAccessInfoEx = null;
        for (SiteInConference siteInConference : siteInConferences)
        {
            //siteInfo = new SiteInfoEx();
            siteAccessInfoEx = new SiteAccessInfoEx();
            
            //siteInfo.setUri(siteInConference.getUri());
            //siteInfo.setName(siteInConference.getName());
            // 返回多个accessCode，考虑多MCU的情况
            siteAccessInfoEx.setUri(siteInConference.getUri());
            siteAccessInfoEx.setConfAccessCode(siteInConference.getAccessCode());
            siteAccessInfoEx.setName(siteInConference.getName());
            siteAccessInfoEx.setBeginTime(DateUtils.toGregorianCalendarDateSMC(siteInConference.getBeginTime()));
            siteAccessInfoEx.setMcuUri(siteInConference.getMcuUri());
            //conferenceInfo.getSites().add(siteInfo);
            conferenceInfo.getSiteAccessInfos().add(siteAccessInfoEx);
        }
        
        //add in r3
        conferenceInfo.setRecorderAddr(conference.getRecorderAddr());
        
        scheduleConfResponse.setRecurrenceConfInfo(conferenceInfo);
    }
    
    /**
     * 预约会议，修改会议共用 北向领域bean转北向soap bean，用于返回的情况
     */
    private ScheduleConfExResponse scheduleConfCommModel2soap(SDKResult<ScheduleConference> result)
    {
        ScheduleConfExResponse scheduleConfResponse = new ScheduleConfExResponse();
        setConferenceEx(result.getErrCode(), result.getResult(), scheduleConfResponse);
        return scheduleConfResponse;
    }
    
    /**
     * 预约周期会议，model2soap 预约会议，修改会议共用 北向领域bean转北向soap bean，用于返回的情况
     */
    private ScheduleRecurrenceConferenceExResponse scheduleRecurrenceConfCommModel2soap(
        SDKResult<PeriodicalConference> result)
    {
        ScheduleRecurrenceConferenceExResponse scheduleRecurrenceConferenceExResponse =
            new ScheduleRecurrenceConferenceExResponse();
        setRecurrenceConfInfo(result.getErrCode(), result.getResult(), scheduleRecurrenceConferenceExResponse);
        scheduleRecurrenceConferenceExResponse.setRecurrenceConfInfo(scheduleRecurrenceConferenceExResponse.getRecurrenceConfInfo());
        return scheduleRecurrenceConferenceExResponse;
    }
    
    /**
     * 预约会议，北向soapbean转北向领域bean 用于赋值的情况 ModelBean soap2model(SoapBean){}
     * 预约会议，北向soapbean转北向领域bean 用于赋值的情况 ModelBean soap2model(SoapBean){}
     */
    public ScheduleConference scheduleConfSoap2model(ScheduleConfEx parameters)
        throws Exception
    {
        ScheduleConference scheduleConference = new ScheduleConference();
        conferenceInfoExSoap2model(parameters.getScheduleConf(), scheduleConference);
        return scheduleConference;
    }
    
    /**
     * 预约会议，北向领域bean转北向soap bean 用于返回的情况 response model2soap
     */
    public ScheduleConfExResponse scheduleConferenceModel2soap(SDKResult<ScheduleConference> result)
    {
        return scheduleConfCommModel2soap(result);
    }
    
    /**
     * 预约周期会议， 北向soapbean转北向领域bean 用于赋值的情况 ModelBean soap2model(SoapBean){}
     */
    public PeriodicalConference scheduleRecurrenceConfSoap2model(ScheduleRecurrenceConferenceEx parameters)
        throws Exception
    {
        return scheduleRecurrenceConfCommSoap2model(parameters);
    }
    
    /**
     * 预约周期会议，北向领域bean转北向soap bean 用于返回的情况 response model2soap
     */
    public ScheduleRecurrenceConferenceExResponse scheduleRecurrenceConfModel2soap(
        SDKResult<PeriodicalConference> result)
    {
        
        return scheduleRecurrenceConfCommModel2soap(result);
    }
    
    /**
     * 修改会议，北向soapbean转北向领域bean 用于赋值的情况 ModelBean soap2model(SoapBean){}
     * 修改会议，北向soapbean转北向领域bean 用于赋值的情况 ModelBean soap2model(SoapBean){}
     */
    public ScheduleConference editScheduledConfSoap2model(EditScheduledConfEx parameters)
        throws Exception
    {
        ScheduleConference scheduleConference = new ScheduleConference();
        conferenceInfoExSoap2model(parameters.getEditConf(), scheduleConference);
        return scheduleConference;
    }
    
    /**
     * 预约带匿名会场的会议，北向领域bean转北向soap bean 用于返回的情况 response model2soap
     */
    public EditScheduledConfExResponse editScheduledConfModel2soap(SDKResult<ScheduleConference> result)
    {
        EditScheduledConfExResponse editScheduleConfResponse = new EditScheduledConfExResponse();
        ScheduleConfExResponse scheduleConfResponse = scheduleConfCommModel2soap(result);
        
        editScheduleConfResponse.setConferenceInfo(scheduleConfResponse.getConferenceInfo());
        editScheduleConfResponse.setResultCode(scheduleConfResponse.getResultCode());
        return editScheduleConfResponse;
    }
    
    /**
     * 修改周期会议，北向soapbean转北向领域bean 用于赋值的情况 ModelBean soap2model(SoapBean){}
     * 修改会议，北向soapbean转北向领域bean 用于赋值的情况 ModelBean soap2model(SoapBean){}
     */
    public PeriodicalConference editScheduledRecurrenceConfSoap2model(EditRecurrenceConferenceEx parameters)
        throws Exception
    {
        ScheduleRecurrenceConferenceEx scheduleRecurrenceConferenceEx = new ScheduleRecurrenceConferenceEx();
        scheduleRecurrenceConferenceEx.setScheduleConf(parameters.getEditConf());
        
        return scheduleRecurrenceConfCommSoap2model(scheduleRecurrenceConferenceEx);
    }
    
    /**
     * 修改周期会议，北向领域bean转北向soap bean 用于返回的情况 response model2soap
     */
    public EditRecurrenceConferenceExResponse editScheduledRecurrenceConfModel2soap(
        SDKResult<PeriodicalConference> result)
    {
        EditRecurrenceConferenceExResponse editScheduleConfResponse = new EditRecurrenceConferenceExResponse();
        ScheduleRecurrenceConferenceExResponse scheduleConfResponse = scheduleRecurrenceConfCommModel2soap(result);
        
        editScheduleConfResponse.setRecurrenceConfInfo(scheduleConfResponse.getRecurrenceConfInfo());
        editScheduleConfResponse.setResultCode(scheduleConfResponse.getResultCode());
        return editScheduleConfResponse;
    }
    
    public DateTimeRange querySiteStatusSoap2model(XMLGregorianCalendar beginTime, Duration duration)
    {
        if (null == beginTime || null == duration)
        {
            return null;
        }
        DateTimeRange timeRange = new DateTimeRange();
        //开始时间转换 减8小时
        timeRange.setStart(DateUtils.toDateSMC(beginTime));
        timeRange.setSpan(duration.toString());
        return timeRange;
    }
    
    public QuerySiteStatusExResponse querySiteStatusModel2soap(SDKResult<List<Site>> result)
    {
        QuerySiteStatusExResponse response = new QuerySiteStatusExResponse();
        response.setResultCode((int)result.getErrCode());
        if (0 == response.getResultCode())
        {
            SiteFreeBusyStatesEx siteFreeBusyStatesEx = null;
            FreeBusyStateEx freeBusyStateEx = null;
            for (Site site : result.getResult())
            {
                siteFreeBusyStatesEx = new SiteFreeBusyStatesEx();
                siteFreeBusyStatesEx.setUri(site.getUri());
                
                if (null != site.getFreeBusyInfoList())
                {
                    for (FreeBusyInfo freeBusyInfo : site.getFreeBusyInfoList())
                    {
                        freeBusyStateEx = new FreeBusyStateEx();
                        freeBusyStateEx.setConfId(freeBusyInfo.getConfInternalId());
                        freeBusyStateEx.setConfName(freeBusyInfo.getConfName());
                        // 会议开始时间转换 加8小时
                        freeBusyStateEx.setStartTime(DateUtils.toGregorianCalendarDatePlusTimezone(freeBusyInfo.getTimeRange()
                            .getStart()));
                        freeBusyStateEx.setSpan(DurationUtils.durationStr2dur(freeBusyInfo.getTimeRange().getSpan()));
                        freeBusyStateEx.setState(FreeBusyStateMapping.enum2Int(FreeBusyState.valueOf(freeBusyInfo.getFreeBusyState())));
                        siteFreeBusyStatesEx.getStates().add(freeBusyStateEx);
                    }
                }
                
                response.getSiteFreeBusyStates().add(siteFreeBusyStatesEx);
            }
            
        }
        
        return response;
    }
    
    public DateTimeRange synchSiteStatusSoap2model(XMLGregorianCalendar beginTime, Duration duration)
    {
        DateTimeRange timeRange = new DateTimeRange();
        //开始时间转换 减8小时
        timeRange.setStart(DateUtils.toDateSMC(beginTime));
        if (null != duration)
        {
            timeRange.setSpan(duration.toString());
        }
        return timeRange;
    }
    
    public SynchSiteStatusExResponse synchSiteStatusModel2soap(SDKResult<List<Site>> result)
    {
        SynchSiteStatusExResponse response = new SynchSiteStatusExResponse();
        response.setResultCode((int)result.getErrCode());
        if (0 == response.getResultCode() && null != result.getResult())
        {
            SiteFreeBusyStatesEx siteFreeBusyStatesEx = null;
            FreeBusyStateEx freeBusyStateEx = null;
            for (Site site : result.getResult())
            {
                siteFreeBusyStatesEx = new SiteFreeBusyStatesEx();
                siteFreeBusyStatesEx.setUri(site.getUri());
                
                if (null != site.getFreeBusyInfoList())
                {
                    for (FreeBusyInfo freeBusyInfo : site.getFreeBusyInfoList())
                    {
                        freeBusyStateEx = new FreeBusyStateEx();
                        freeBusyStateEx.setConfId(freeBusyInfo.getConfInternalId());
                        freeBusyStateEx.setConfName(freeBusyInfo.getConfName());
                        // 会议开始时间转换 加8小时
                        freeBusyStateEx.setStartTime(DateUtils.toGregorianCalendarDatePlusTimezone(freeBusyInfo.getTimeRange()
                            .getStart()));
                        freeBusyStateEx.setSpan(DurationUtils.durationStr2dur(freeBusyInfo.getTimeRange().getSpan()));
                        freeBusyStateEx.setState(FreeBusyStateMapping.enum2Int(FreeBusyState.BUSY));
                        siteFreeBusyStatesEx.getStates().add(freeBusyStateEx);
                    }
                }
                response.getSiteFreeBusyStates().add(siteFreeBusyStatesEx);
            }
            
        }
        
        return response;
    }
    
    public QueryConferencesStatusExResponse queryConferencesStatusModel2soap(SDKResult<List<Conference>> result)
    {
        QueryConferencesStatusExResponse response = new QueryConferencesStatusExResponse();
        response.setResultCode((int)result.getErrCode());
        
        // 返回成功和会议不存在，都需要转换
        if (0 == response.getResultCode() || ErrInfo.CONFERENCE_ID_IS_NOT_EXIST_ERRORCODE == response.getResultCode())
        {
            if (ErrInfo.CONFERENCE_ID_IS_NOT_EXIST_ERRORCODE == response.getResultCode())
            {
                 response.setResultCode(0);
            }
            ConferenceStatusEx conferenceStatus = null;
            ConferenceStatus status = null;
            for (Conference conference : result.getResult())
            {
                status = conference.getConferenceStatus();
                conferenceStatus = new ConferenceStatusEx();
                
                conferenceStatus.setBroadcast(status.getBroadcast());
                conferenceStatus.setChair(status.getChair());
                conferenceStatus.setId(status.getId());
                conferenceStatus.setIsAudioSwitch(status.getIsAudioSwitch());
                conferenceStatus.setIsLock(status.getIsLock());
                conferenceStatus.setName(status.getName());
                conferenceStatus.setPresentation(status.getPresentation());
                conferenceStatus.setSpeaking(status.getSpeaking());
                conferenceStatus.setStatus(ConfStatusMapping.str2Int(status.getStatus()));
                conferenceStatus.setSwitchGate(status.getSwtichGate());
                
                //C30新增
                conferenceStatus.setBeginTime(DateUtils.toGregorianCalendarDateSMC(status.getBeginTime()));
                conferenceStatus.setEndTime(DateUtils.toGregorianCalendarDateSMC(status.getEndTime()));
                
                // DTS2015012910778，缺少节点isLockPresentation、lockPresentation
                conferenceStatus.setIsLockPresentation(status.getIsLockPresentation());
                conferenceStatus.setLockPresentation(status.getLockPresentation());
                // end
                
                response.getConferenceStatuses().add(conferenceStatus);
            }
        }
        return response;
    }
    
    public QueryConfSitesStatusExResponse queryConfSitesStatusModel2soap(SDKResult<List<SiteInConference>> result)
    {
        
        QueryConfSitesStatusExResponse response = new QueryConfSitesStatusExResponse();
        response.setResultCode((int)result.getErrCode());
        if (0 == response.getResultCode() && null != result.getResult())
        {
            List<SiteInConference> confSites = result.getResult();
            SiteStatusEx siteStatus = null;
            for (SiteInConference site : confSites)
            {
                siteStatus = new SiteStatusEx();
                siteStatus.setIsMute(site.getIsMute());
                siteStatus.setIsQuiet(site.getIsQuiet());
                siteStatus.setName(site.getName());
                siteStatus.setStatus(site.getStatus());
                siteStatus.setType(SiteTypeMapping.string2Int(site.getSiteType()));
                siteStatus.setUri(site.getUri());
                siteStatus.setVideoSource(site.getVideoSource());
                siteStatus.setVolume(site.getVolume());
                
                //C30新增
                siteStatus.setIsLocalVideoOpen(site.getIsLocalVideoOpen());
                
                // DTS2015012910778，缺少新增节点participantType、screens
                // DTS2015022803348，当会场不存在时，调用该接口返回2130000010空指针错误
                if (null != site.getParticipantType())
                {
                    siteStatus.setParticipantType(ParticipantTypeMapping.string2Int(site.getParticipantType()));
                }
                siteStatus.setScreens(site.getScreens());
                // end
                
                if (null != site.getCallFailedReason())
                {
                    ErrorInfoEx errorInfoEx = new ErrorInfoEx();
                    errorInfoEx.setErrCode((int)((long)site.getCallFailedReason().getErrCode()));
                    errorInfoEx.setDiscription(site.getCallFailedReason().getDiscription());
                    siteStatus.setCallFailedReason(errorInfoEx);
                }
                
                response.getSiteStatuses().add(siteStatus);
            }
        }
        
        return response;
    }
    
    /**
     * 
     * * @param sites /** * @return
     */
    public QuerySitesExResponse sdkResult2QuerySitesExResponse(SDKResult<PagedList<Site>> sites)
    {
        QuerySitesExResponse response = new QuerySitesExResponse();
        List<SiteInfoEx> siteInfoExs = new ArrayList<SiteInfoEx>();
        response.setResultCode(Integer.parseInt(String.valueOf(sites.getErrCode())));
        
        if (null != sites.getResult().getRecords() && sites.getResult().getRecords().size() > 0)
        {
            List<Site> records = sites.getResult().getRecords();
            SiteInfoEx siteInfo = null;
            for (int i = 0; i < records.size(); i++)
            {
                siteInfo = new SiteInfoEx();
                siteInfo.setName(records.get(i).getName());
                siteInfo.setUri(records.get(i).getUri());
                siteInfo.setType(SiteTypeMapping.string2Int(records.get(i).getSiteType()));
                //C30新增
                siteInfo.setRate(records.get(i).getRate());
                siteInfoExs.add(siteInfo);
            }
        }
        response.getSiteInfos().addAll(siteInfoExs);
        return response;
    }
    
    /**
     * 向会议添加会场，北向soapbean转北向领域bean 用于赋值的情况 ModelBean soap2model(SoapBean){}
     */
    public Site addSiteToConfSoap2model(SiteInfoEx siteInfo)
        throws SDKException
    {
        
        Site site = new Site(siteInfo.getUri());
        // 为领域模型Site赋值
        site.setName(siteInfo.getName());
        // 判断枚举类型是否超出范围
        EnumRangeUtils.enumRange(siteInfo.getType(), SiteTypeMapping.class);
        SiteType siteType = SiteTypeMapping.int2Enum(siteInfo.getType());
        site.setSiteType(null == siteType ? null : siteType.toString());
        
        // 判断枚举类型是否超出范围
        EnumRangeUtils.enumRange(siteInfo.getDialingMode(), DialModeMapping.class);
        DialMode dialMode = DialModeMapping.int2Enum(siteInfo.getDialingMode());
        site.setDialingMode(null == dialMode ? null : dialMode.toString());
        
        // 判断枚举类型是否超出范围
        EnumRangeUtils.enumRange(siteInfo.getFrom(), SiteFromMapping.class);
        SiteFrom siteFrom = SiteFromMapping.int2Enum(siteInfo.getFrom());
        site.setFrom(null == siteFrom ? null : siteFrom.toString());
        
        site.setRate(siteInfo.getRate());
        
        site.setVideoFormat(siteInfo.getVideoFormat());
        
        site.setVideoProtocol(siteInfo.getVideoProtocol());
        
        // R5C00新增
        ParticipantType participantType = ParticipantTypeMapping.int2Enum(siteInfo.getParticipantType());
        site.setParticipantType(null == participantType ? null : participantType.toString());
        site.setIsLockVideoSource(siteInfo.getIsLockVideoSource());
        // R5C00 end
        
        return site;
    }
    
    /**
     * 向会议添加会场，北向领域bean转北向soapbean
     */
    public AddSiteToConfExResponse model2AddSiteToConfSoap(SDKResult<List<SiteInConference>> result)
    {
        AddSiteToConfExResponse response = new AddSiteToConfExResponse();
        response.setResultCode((int)result.getErrCode());
        if (0 == result.getErrCode())
        {
            List<SiteInConference> siteInConflist = result.getResult();
            for (SiteInConference sitconf : siteInConflist)
            {
                SiteAccessInfoEx siteAccessInfoEx = new SiteAccessInfoEx();
                siteAccessInfoEx.setUri(sitconf.getUri());
                siteAccessInfoEx.setBeginTime(DateUtils.toGregorianCalendarDateSMC(sitconf.getBeginTime()));
                siteAccessInfoEx.setConfAccessCode(sitconf.getConfAccessCode());
                siteAccessInfoEx.setMcuUri(sitconf.getMcuUri());
                
                response.getSiteAccessInfos().add(siteAccessInfoEx);
            }
        }
        return response;
    }
    
    public QueryAdhocConfFreeBusyExResponse queryAdhocConfFreeBusyExModal2Soap(
        SDKResult<AdhocConfFreeBusyStateList> result)
    {
        QueryAdhocConfFreeBusyExResponse response = new QueryAdhocConfFreeBusyExResponse();
        response.setResultCode((int)result.getErrCode());
        
        if (null != result.getResult())
        {
            List<AdhocConfFreeBusyState> list = result.getResult().getAdhocConfFreeBusyStates();
            
            if (null != list && !list.isEmpty())
            {
                AdhocConfFreeBusyStateEx adhocConfFreeBusyStateEx = null;
                FreeBusyStateEx stateEx = null;
                
                for (AdhocConfFreeBusyState state : list)
                {
                    adhocConfFreeBusyStateEx = new AdhocConfFreeBusyStateEx();
                    adhocConfFreeBusyStateEx.setConfAccessCode(state.getConfAccessCode());
                    
                    List<com.huawei.esdk.tp.domain.model.bean.FreeBusyState> freeBusyList = state.getFreeBusyState();
                    if (null != freeBusyList && !freeBusyList.isEmpty())
                    {
                        for (com.huawei.esdk.tp.domain.model.bean.FreeBusyState busyState : freeBusyList)
                        {
                            stateEx = new FreeBusyStateEx();
                            stateEx.setConfId(busyState.getConfId());
                            stateEx.setConfName(busyState.getConfName());
                            stateEx.setState(busyState.getState());
                            stateEx.setSpan(busyState.getSpan());
                            stateEx.setStartTime(busyState.getStartTime());
                            adhocConfFreeBusyStateEx.getFreebusys().add(stateEx);
                        }
                    }
                    
                    response.getFreebusy().add(adhocConfFreeBusyStateEx);
                }
            }
        }
        
        return response;
    }
    
    /**
     * 查询Adhoc会议忙闲状态变化的数据
     */
    public SynchAdhocConfFreeBusyExResponse synchAdhocConfFreeBusyExModal2Soap(
        SDKResult<AdhocConfFreeBusyStateList> result)
    {
        SynchAdhocConfFreeBusyExResponse response = new SynchAdhocConfFreeBusyExResponse();
        response.setResultCode((int)result.getErrCode());
        AdhocConfFreeBusyStateList sdkResult = result.getResult();
        if (null == sdkResult)
        {
            return response;
        }
        
        List<AdhocConfFreeBusyState> list = result.getResult().getAdhocConfFreeBusyStates();
        
        if (null != list && !list.isEmpty())
        {
            AdhocConfFreeBusyStateEx adhocConfFreeBusyStateEx = null;
            FreeBusyStateEx stateEx = null;
            
            for (AdhocConfFreeBusyState state : list)
            {
                adhocConfFreeBusyStateEx = new AdhocConfFreeBusyStateEx();
                adhocConfFreeBusyStateEx.setConfAccessCode(state.getConfAccessCode());
                
                List<com.huawei.esdk.tp.domain.model.bean.FreeBusyState> freeBusyList = state.getFreeBusyState();
                if (null != freeBusyList && !freeBusyList.isEmpty())
                {
                    for (com.huawei.esdk.tp.domain.model.bean.FreeBusyState busyState : freeBusyList)
                    {
                        stateEx = new FreeBusyStateEx();
                        stateEx.setConfId(busyState.getConfId());
                        stateEx.setConfName(busyState.getConfName());
                        stateEx.setState(busyState.getState());
                        stateEx.setSpan(busyState.getSpan());
                        stateEx.setStartTime(busyState.getStartTime());
                        adhocConfFreeBusyStateEx.getFreebusys().add(stateEx);
                    }
                }
                
                response.getFreebusy().add(adhocConfFreeBusyStateEx);
            }
        }
        
        return response;
    }
    
    /**
     * 查询Ad hoc类型的会议列表
     * @throws SDKException 
     */
    public QuerySites queryAdhocConferencesExSoap2Modal(QueryAdhocConferencesEx parameters)
        throws SDKException
    {
        
        QuerySites querySites = new QuerySites();
        QueryConfigEx queryConfig = parameters.getQueryConfig();
        
        PageParamEx pageInfo = queryConfig.getPageParam();
        querySites.setCurrentPage(pageInfo.getCurrentPage());
        querySites.setNumberPerPage(pageInfo.getNumberPerPage());
        
        List<SortItemEx> sortItems = queryConfig.getSortItems();
        if (!sortItems.isEmpty())
        {
            List<SortField> sortItemsModal = new ArrayList<SortField>();
            for (SortItemEx stItem : sortItems)
            {
                Integer itemIndex = stItem.getItemIndex();
                Integer sort = stItem.getSort();
                
                // DTS2015012705306
                // 非必填参数不为空时，北向转换时校验其必填属性
                if (null == itemIndex || null == sort)
                {
                    SDKException sdkException = new SDKException(ErrInfo.SDK_PARAM_NOT_COMPLETE_ERRORDESC);
                    sdkException.setSdkErrCode(ErrInfo.SDK_PARAM_NOT_COMPLETE_ERRORCODE);
                    throw sdkException;
                }
                
                SortField sortField = new SortField();
                sortField.setIsAscend(sort);
                sortField.setFieldIndex(itemIndex);
                sortItemsModal.add(sortField);
            }
            querySites.setSortField(sortItemsModal);
        }
        
        List<FilterBaseEx> filters = queryConfig.getFilters();
        if (!filters.isEmpty())
        {
            List<QueryCondition> queryConditions = new ArrayList<QueryCondition>();
            for (FilterBaseEx ftItem : filters)
            {
                Integer columnIndex = ftItem.getColumnIndex();
                
                // DTS2015012705306
                // 非必填参数不为空时，北向转换时校验其必填属性
                if (null == columnIndex)
                {
                    SDKException sdkException = new SDKException(ErrInfo.SDK_PARAM_NOT_COMPLETE_ERRORDESC);
                    sdkException.setSdkErrCode(ErrInfo.SDK_PARAM_NOT_COMPLETE_ERRORCODE);
                    throw sdkException;
                }
                
                QueryCondition queryCondition = getQueryConditionSoap2Modal(ftItem);
                if (null != queryCondition)
                {
                    queryConditions.add(queryCondition);
                }
            }
            querySites.setQueryCondition(queryConditions);
        }
        
        if (null != queryConfig.getFocusItem())
        {
            querySites.setFocusItem((long)queryConfig.getFocusItem());
        }
        
        return querySites;
        
    }
    
    private QueryCondition getQueryConditionSoap2Modal(FilterBaseEx filtersEx)
    {
        if (StringFilterEx.class.isInstance(filtersEx))
        {
            StringFilterEx filtersEx1 = (StringFilterEx)filtersEx;
            QueryCondition queryCondition = new QueryCondition();
            queryCondition.setConditionName("StringFilterEx");
            queryCondition.setConditionType("1");
            queryCondition.setConditionValue(new Object[] {filtersEx1.getColumnIndex(), filtersEx1.getValue()});
            return queryCondition;
        }
        else if (IntFilterEx.class.isInstance(filtersEx))
        {
            IntFilterEx filtersEx1 = (IntFilterEx)filtersEx;
            QueryCondition queryCondition = new QueryCondition();
            queryCondition.setConditionName("IntFilterEx");
            queryCondition.setConditionType("2");
            queryCondition.setConditionValue(new Object[] {filtersEx1.getColumnIndex(), filtersEx1.getGreaterThan(),
                filtersEx1.getLessThan(), filtersEx1.getEqualTo()});
            return queryCondition;
        }
        else if (DoubleFilterEx.class.isInstance(filtersEx))
        {
            DoubleFilterEx filtersEx1 = (DoubleFilterEx)filtersEx;
            QueryCondition queryCondition = new QueryCondition();
            queryCondition.setConditionName("DoubleFilterEx");
            queryCondition.setConditionType("3");
            queryCondition.setConditionValue(new Object[] {filtersEx1.getColumnIndex(), filtersEx1.getGreaterThan(),
                filtersEx1.getLessThan(), filtersEx1.getEqualTo()});
            return queryCondition;
        }
        else
        {
            return null;
        }
        
    }
    
    public QueryAdhocConferencesExResponse queryAdhocConferencesExModal2Soap(SDKResult<AdhocConferencesList> result)
    {
        QueryAdhocConferencesExResponse response = new QueryAdhocConferencesExResponse();
        response.setResultCode((int)result.getErrCode());
        
        AdhocConferenceEx adhocConferenceEx = null;
        
        List<AdhocConferences> adhocConferences = result.getResult().getAdhocConferences();
        if (null != adhocConferences && !adhocConferences.isEmpty())
        {
            for (AdhocConferences adhocConference : adhocConferences)
            {
                adhocConferenceEx = new AdhocConferenceEx();
                if (null != adhocConference)
                {
                    adhocConferenceEx.setName(adhocConference.getName());
                    adhocConferenceEx.setConfAccessCode(adhocConference.getConfAccessCode());
                }
                response.getAdhocConferences().add(adhocConferenceEx);
            }
        }
        
        PagesInfoEx pageInfo = new PagesInfoEx();
        PagesInfo pagesInfo = result.getResult().getPagesInfo();
        if (null != pagesInfo)
        {
            pageInfo.setCurrentPage(pagesInfo.getCurrentPage());
            pageInfo.setTotalPages(pagesInfo.getTotalPages());
            pageInfo.setTotalRecords(pagesInfo.getTotalRecords());
        }
        
        response.setPageInfo(pageInfo);
        
        return response;
    }
    
    public MultiPointCDRQueryConfig queryMultiPointCDRExSoap2Model(MultiPointCDRQueryConfigEx queryConfig)
    {
        MultiPointCDRQueryConfig config = new MultiPointCDRQueryConfig();
        
        Integer duration = DurationUtils.duration2int(queryConfig.getDuration());
        Date beginTime = DateUtils.toDate(queryConfig.getBeginTime());
        config.setBeginTime(beginTime);
        config.setDuration(duration);
        
        if (null != queryConfig.getSiteUri())
        {
            config.setSiteUri(queryConfig.getSiteUri());
        }
        
        if (null != queryConfig.getPageParam())
        {
            PageParam pageParam = new PageParam();
            pageParam.setCurrentPage(queryConfig.getPageParam().getCurrentPage());
            pageParam.setNumberPerPage(queryConfig.getPageParam().getNumberPerPage());
            
            config.setPageParam(pageParam);
        }
        
        return config;
    }
    
    public GetContinuousPresenceInfoExResponse getContinuousPresenceInfoExModal2Soap(
        SDKResult<ContinuousPresenceCapability> result)
    {
        GetContinuousPresenceInfoExResponse response = new GetContinuousPresenceInfoExResponse();
        
        // 转换错误码
        response.setResultCode((int)result.getErrCode());
        
        if (0 == result.getErrCode())
        {
            ContinuousPresenceCapability capability = result.getResult();
            
            // 转换cpResource
            response.setCpResource(capability.getCpResource());
            
            // 转换target
            for (String str : capability.getTargets())
            {
                if (ConfigManager.getInstance().getValue("professional.setContinuousPresence.target_(%CP)").equals(str))
                {
                    // (%CP)转换成空串，转换成0会有默认不是第0组多画面的问题，会有歧义
                    response.getTargets().add("");
                }
                else if (str.endsWith(ConfigManager.getInstance()
                    .getValue("professional.setContinuousPresence.target_%CP)")))
                {
                    // 需要将(xxxxx%CP)过滤成(xxxxx)
                    str =
                        str.replaceAll(ConfigManager.getInstance()
                            .getValue("professional.setContinuousPresence.target_%CP"),
                            "");
                    response.getTargets().add(str);
                }
                else if (str.startsWith(ConfigManager.getInstance()
                    .getValue("professional.setContinuousPresence.target_(%CP")))
                {
                    // (%CPx)过滤成x
                    str =
                        str.replaceAll("\\"
                            + ConfigManager.getInstance().getValue("professional.setContinuousPresence.target_(%CP"),
                            "");
                    str =
                        str.replaceAll("\\"
                            + ConfigManager.getInstance().getValue("professional.setContinuousPresence.target_)"),
                            "");
                    response.getTargets().add(str);
                }
                else
                {
                    response.getTargets().add(str);
                }
            }
            
            // 转换supportCPMode
            for (ContinuousPresenceMode mode : capability.getSupportCPModes())
            {
                response.getSupportCPModes().add(ContinuousPresenceModeEXMapping.getInstance().enum2Int(mode.value()));
            }
        }
        
        return response;
    }
    
    public GetContinuousPresenceParamExResponse getContinuousPresenceParamExModal2Soap(
        SDKResult<ContinuousPresenceParam> result)
    {
        GetContinuousPresenceParamExResponse response = new GetContinuousPresenceParamExResponse();
        response.setResultCode((int)result.getErrCode());
        
        if (0 == result.getErrCode())
        {
            ContinuousPresenceParam param = result.getResult();
            response.setPresenceMode(param.getPresenceMode());
            
            if (null != param.getSubPics())
            {
                for (String str : param.getSubPics())
                {
                    response.getSubPics().add(str);
                }
            }
        }
        
        return response;
    }
    
    public QueryConfSiteMCUExResponse queryConfSiteMCUExModal2Soap(SDKResult<List<SiteMCU>> result)
    {
        QueryConfSiteMCUExResponse response = new QueryConfSiteMCUExResponse();
        response.setResultCode((int)result.getErrCode());
        if (0 == result.getErrCode() && null != result.getResult())
        {
            for (SiteMCU siteMCUModal : result.getResult())
            {
                SiteMCUEx siteMCUSoap = new SiteMCUEx();
                siteMCUSoap.setMcuId((int)((long)siteMCUModal.getMcuId()));
                siteMCUSoap.setSiteUri(siteMCUModal.getSiteUri());
                response.getMcus().add(siteMCUSoap);
            }
        }
        return response;
    }
    
    public PointToPointCDRQueryConfig queryPointToPointCDRExSopa2Modal(QueryPointToPointCDREx parameters)
    {
        PointToPointCDRQueryConfig queryConfig = new PointToPointCDRQueryConfig();
        
        PointToPointCDRQueryConfigEx queryConfigSoap = parameters.getQueryConfig();
        queryConfig.setBeginTime(DateUtils.toDate(queryConfigSoap.getBeginTime()));
        queryConfig.setDuration(DurationUtils.duration2int(queryConfigSoap.getDuration()));
        
        if (null != queryConfigSoap.getPageParam())
        {
            PageParam pageParam = new PageParam();
            pageParam.setCurrentPage(queryConfigSoap.getPageParam().getCurrentPage());
            pageParam.setNumberPerPage(queryConfigSoap.getPageParam().getNumberPerPage());
            queryConfig.setPageParam(pageParam);
        }
        
        if (null != queryConfigSoap.getPageParam())
        {
            PageParam pageParam = new PageParam();
            pageParam.setCurrentPage(queryConfigSoap.getPageParam().getCurrentPage());
            pageParam.setNumberPerPage(queryConfigSoap.getPageParam().getNumberPerPage());
            queryConfig.setPageParam(pageParam);
        }
        
        if (null != queryConfigSoap.getEndPoint())
        {
            CallEndPoint callEndPoint = new CallEndPoint();
            callEndPoint.setSiteUri(queryConfigSoap.getEndPoint().getSiteUri());
            callEndPoint.setType(queryConfigSoap.getEndPoint().getType());
            queryConfig.setCallEndPoint(callEndPoint);
        }
        
        return queryConfig;
    }
    
    public QueryPointToPointCDRExResponse queryPointToPointCDRExModal2Soap(SDKResult<PagedList<PointToPointCDR>> result)
    {
        QueryPointToPointCDRExResponse response = new QueryPointToPointCDRExResponse();
        if (null == result)
        {
            response.setResultCode(ESDKErrorCodeConstant.ERROR_CODE_NETWORK_ERROR);
            return response;
        }
        
        response.setResultCode((int)result.getErrCode());
        if (0 == response.getResultCode())
        {
            PagesInfoEx pageInfoSoap = new PagesInfoEx();
            pageInfoSoap.setCurrentPage(result.getResult().getCurPageNo());
            pageInfoSoap.setTotalPages(result.getResult().getTotalPageCount());
            pageInfoSoap.setTotalRecords(result.getResult().getTotalRecordCount());
            response.setPageInfo(pageInfoSoap);
            
            if (null != result.getResult().getRecords())
            {
                for (PointToPointCDR item : result.getResult().getRecords())
                {
                    PointToPointCDREx pointToPointCDREx = new PointToPointCDREx();
                    pointToPointCDREx.setCalledProtocol(item.getCalledProtocol());
                    pointToPointCDREx.setCalledUri(item.getCalledUri());
                    pointToPointCDREx.setCallingProtocol(item.getCallingProtocol());
                    pointToPointCDREx.setCallingUri(item.getCallingUri());
                    pointToPointCDREx.setEndTime(DateUtils.toGregorianCalendarDateSMC(item.getEndTime()));
                    pointToPointCDREx.setRate(item.getRate());
                    pointToPointCDREx.setStartTime(DateUtils.toGregorianCalendarDateSMC(item.getStartTime()));
                    response.getCdr().add(pointToPointCDREx);
                }
            }
        }
        return response;
    }
    
    public QueryMultiPointCDRExResponse queryMultiPointCDRExModel2Soap(SDKResult<MultiPointCDRResult> result)
    {
        QueryMultiPointCDRExResponse response = new QueryMultiPointCDRExResponse();
        
        if (null == result)
        {
            response.setResultCode(ESDKErrorCodeConstant.ERROR_CODE_NETWORK_ERROR);
            return response;
        }
        
        response.setResultCode((int)result.getErrCode());
        
        if (null != result.getResult())
        {
            MultiPointCDRResult cdrResult = result.getResult();
            
            if (null != cdrResult.getMultiPointCDRList() && !cdrResult.getMultiPointCDRList().isEmpty())
            {
                MultiPointCDREx cdrEx = null;
                List<MultiPointCDR> multiPointCDRs = cdrResult.getMultiPointCDRList();
                
                for (MultiPointCDR cdr : multiPointCDRs)
                {
                    cdrEx = new MultiPointCDREx();
                    cdrEx.setBillCode(cdr.getBillCode());
                    cdrEx.setConferenceCreater(cdr.getConferenceCreater());
                    cdrEx.setConferenceId(cdr.getConferenceId());
                    cdrEx.setConferenceName(cdr.getConferenceName());
                    cdrEx.setEndTime(DateUtils.toGregorianCalendarDateSMC(DateUtils.toDate(cdr.getEndTime())));
                    cdrEx.setStartTime(DateUtils.toGregorianCalendarDateSMC(DateUtils.toDate(cdr.getStartTime())));
                    cdrEx.setParticipantType(cdr.getParticipantType());
                    cdrEx.setRate(cdr.getRate());
                    cdrEx.setSiteName(cdr.getSiteName());
                    cdrEx.setSiteType(SiteTypeMapping.string2Int(cdr.getSiteType()));
                    cdrEx.setSiteUri(cdr.getSiteUri());
                    response.getCdr().add(cdrEx);
                }
            }
            
            if (null != cdrResult.getPagesInfo())
            {
                PagesInfoEx pagesInfoEx = new PagesInfoEx();
                pagesInfoEx.setCurrentPage(cdrResult.getPagesInfo().getCurrentPage());
                pagesInfoEx.setTotalPages(cdrResult.getPagesInfo().getTotalPages());
                pagesInfoEx.setTotalRecords(cdrResult.getPagesInfo().getTotalRecords());
                response.setPageInfo(pagesInfoEx);
            }
        }
        
        return response;
    }
}
